﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DAL;
using Entities;
using BUS;
using Utility;

public partial class Administrator_doanhnghiep_themhinhanh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            HiddenField1.Value = id.ToString();
        }
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
    
            HttpFileCollection hfc = Request.Files;
            for (int i = 0; i < hfc.Count; i++)
            {
                HttpPostedFile hpf = hfc[i];
                
                if (hpf.ContentLength > 0)
                {
                    hpf.SaveAs(Server.MapPath("~/Photos/") + System.IO.Path.GetFileName(hpf.FileName));

                    

                    System.Drawing.Image img = System.Drawing.Image.FromFile(
                        Server.MapPath("~/Photos/" + hpf.FileName));

                    ImageUtility.MakeThumbnailPhoto(
                        img, 100, 100, Server.MapPath("~/Photos/Thumbs/"), DateTime.Now.Ticks.ToString() + hpf.FileName);
                    Tbl_ImageDN_Entities imgdn = new Tbl_ImageDN_Entities();

                    imgdn.STT_doanhnghiep = int.Parse(HiddenField1.Value);
                    imgdn.ImagePath = hpf.FileName;

                    Tbl_ImageDN_BUS.Insert(imgdn);
                }
            }
        }
}
